// Copyright (c) 2010 The Chromium OS Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#ifndef THEME_SCOPED_PATH_H_
#define THEME_SCOPED_PATH_H_

#include <cairo.h>

namespace theme {

// ScopedPath releases cairo_path_t it manages when it goes out of scope.
class ScopedPath {
 public:
  ScopedPath() : path_(NULL) {}
  explicit ScopedPath(cairo_path_t* path) : path_(path) {}

  ~ScopedPath() {
    if (path_)
      cairo_path_destroy(path_);
  }

  void reset(cairo_path_t* path) {
    if (path == path_)
      return;
    if (path_)
      cairo_path_destroy(path_);
    path_ = path;
  }

  cairo_path_t* get() { return path_; }

 private:
  cairo_path_t* path_;

  // DISALLOW_COPY_AND_ASSIGN
  void operator=(const ScopedPath& cr);
  ScopedPath(const ScopedPath& cr);
};

}  // namespace theme

#endif  // THEME_SCOPED_PATH_H_
